package top.vanchor.flexible;

import top.vanchor.flexible.utils.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BB {
    public static void main(String[] args) {
        Integer nowYear = Integer.valueOf(DateUtils.dateFormat(new Date(), "yyyy"));
        Integer nowMonth = Integer.valueOf(DateUtils.dateFormat(new Date(), "MM"));

        //计算五年前应该是什么样的
        Integer targetYear = nowYear - 5;
        Integer targetMonth = nowMonth + 1;
        if (targetMonth > 12) {
            targetMonth = 1;
            targetYear++;
        }
        String targetMonthStr = targetMonth >= 10 ? targetMonth + "" : "0" + targetMonth;
        String targetDateStr = targetYear + "-" + targetMonthStr+"-01";

        System.out.println(nowYear + "-" + nowMonth);
        System.out.println(targetDateStr);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date resDate = sdf.parse(targetDateStr);
            System.out.println(resDate);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }
}
